﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ScormModel;
using ScormModel.Question;
using System.Collections.ObjectModel;
namespace WpfELearningAuthoringTool
{
    /// <summary>
    /// Interaction logic for QuestionTypeDialog.xaml
    /// </summary>
    public partial class QuestionTypeDialog : Window
    {
        RibbonBarRegion.RibbonBarHeader parentChild;
        string currentDirectory;
        WebBrowser browser;
        ImsManifest imsmanifest;
        ObservableCollection<QuestionTest> listQuestions;
        bool isAddNew = true;
        public string CurrentDirectory
        {
            get { return this.currentDirectory; }
            set { this.currentDirectory = value; }
        }
        public bool IsAddNew
        {
            get { return this.isAddNew; }
            set { this.isAddNew = value; }
        }
        public WebBrowser WebBrowser
        {
            get { return this.browser; }
            set { this.browser = value; }
        }
        public ImsManifest Imsmanifest
        {
            get { return this.imsmanifest; }
            set { this.imsmanifest = value; }
        }
        public ObservableCollection<QuestionTest> ListQuestions
        {
            get { return this.listQuestions; }
            set { this.listQuestions = value; }
        }
        public RibbonBarRegion.RibbonBarHeader ParentChild
        {
            get { return this.parentChild; }
            set { this.parentChild = value; }
        }
        public QuestionTypeDialog()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (rbSingleChoice.IsChecked == false && rbMultiChoice.IsChecked == false && rbTFChoice.IsChecked == false && rbOrderChoice.IsChecked == false) {
                MessageBox.Show("Please select one question type");
                }
            if (IsAddNew == false)
            {
                QuestionTest qt = new QuestionTest();
                qt.Id = (listQuestions.Count + 1).ToString();
                qt.Description = "Question " + (listQuestions.Count + 1).ToString();
                if (rbSingleChoice.IsChecked == true)
                {
                    qt.QuestionType = "single";
                } 
                else if(rbMultiChoice.IsChecked == true)
                {
                    qt.QuestionType = "multiple";
                } else if (rbTFChoice.IsChecked == true)
                {
                    qt.QuestionType = "true_false";
                }else if (rbOrderChoice.IsChecked == true)
                {
                    qt.QuestionType = "order";                
                }
                qt.QuestionData = new ChoiceQuestionData();
                listQuestions.Add(qt);
                Close();
            }
            else
            {
                if (rbSingleChoice.IsChecked == true)
                {
                    SimpleChoiceQuestionDialog scq = new SimpleChoiceQuestionDialog();
                    scq.ParentChild = parentChild;
                    scq.Owner = parentChild;
                    scq.CurrentDirectory = currentDirectory;
                    scq.WebBrowser = browser;
                    scq.Imsmanifest = imsmanifest;
                    scq.ShowDialog();
                    Close();
                }
                else if (rbMultiChoice.IsChecked == true)
                {
                    MultipleChoiceQuestionDialog mcq = new MultipleChoiceQuestionDialog();
                    mcq.ParentChild = parentChild;
                    mcq.Owner = parentChild;
                    mcq.CurrentDirectory = currentDirectory;
                    mcq.WebBrowser = browser;
                    mcq.Imsmanifest = imsmanifest;
                    mcq.ShowDialog();
                    Close();
                }
                else if (rbTFChoice.IsChecked == true)
                {
                    TrueFalseQuestionDialog tfq = new TrueFalseQuestionDialog();
                    tfq.ParentCHild = parentChild;
                    tfq.Owner = parentChild;
                    tfq.CurrentDirectory = currentDirectory;
                    tfq.WebBrowser = browser;
                    tfq.Imsmanifest = imsmanifest;
                    tfq.ShowDialog();
                    Close();
                }
                else if (rbOrderChoice.IsChecked == true)
                {
                    OrderChoiceQuestionDialog ocq = new OrderChoiceQuestionDialog();
                    ocq.ParentChild = parentChild;
                    ocq.Owner = parentChild;
                    ocq.CurrentDirectory = currentDirectory;
                    ocq.WebBrowser = browser;
                    ocq.Imsmanifest = imsmanifest;
                    ocq.ShowDialog();
                    Close();
                }
                   
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }
    }
}
